package com.etc.dao.impl;
/**
 * 管理员登录的dao
 * author:gmy
 */
import java.sql.ResultSet;
import java.sql.SQLException;
import com.etc.dao.AdminDao;
import com.etc.entity.Admin;
import com.etc.util.DBUtil;

public class AdminDaoImpl implements AdminDao{

	@Override
	public Admin findByMobileAndPassword(String mobile, String password) {
		Admin admin = null;
		ResultSet rs = DBUtil.query("select admin_id,nickname,admin_img_path from admin where mobile=? and admin_password=? ", mobile,password);
		try {
			while (rs.next()) {
				String adminId = rs.getString("admin_id");
				String nickname = rs.getString("nickname");
				String adminImgPath =rs.getString("admin_img_path");
				admin = new Admin();
				admin.setAdminId(adminId);
				admin.setNickname(nickname);
				admin.setMobile(mobile);
				admin.setAdminPassword(password);
				admin.setAdminImgPath(adminImgPath);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return admin;
	}

	@Override
	public int updateById(Admin admin) {
		return DBUtil.update("update admin set admin_id=?,nickname=?,mobile=?,admin_password=?,admin_img_path=? where admin_id=?", 
				admin.getAdminId(),
				admin.getNickname(),
				admin.getMobile(),
				admin.getAdminPassword(),
				admin.getAdminImgPath(),
				admin.getAdminId());
	}

	
}
